#!/bin/bash

cores=${1-1}
cccc=`awk 'BEGIN{for(i=0;i<'$cores';++i)print i;exit}'`

for x in 0
do
  if taskset -c $x echo $x >/dev/null 2>&1
  then
    taskset -c $x sh data-init
  elif cpuset -l $x echo $x >/dev/null 2>&1
  then
    cpuset -l $x sh data-init
  else
    sh data-init
  fi
done

for x in $cccc
do
  if taskset -c $x echo $x >/dev/null 2>&1
  then
    taskset -c $x sh data-run &
  elif cpuset -l $x echo $x >/dev/null 2>&1
  then
    cpuset -l $x sh data-run &
  else
    sh data-run &
  fi
done

wait

sh data-summarize
